function db(sql) {
  return new Promise((resolve, reject) => {
    // 这里写异步代码
    const mysql = require('mysql');
    const conn = mysql.createConnection({
      host: 'localhost',
      user: 'root',
      password: '12345678',
      database: 'sy123'
    });
    conn.connect();
    conn.query(sql, (err, result) => {
      err ? reject(err) : resolve(result);
    });
    conn.end();
  }).catch(err => {
    console.log(err);
  });
}

module.exports = db;